import { render, createVNode } from 'vue'
import Message from './message.vue'
 
let vm
// 使用单例模式，不再重新插入body
function getMessageInstance () {
  if (vm) return
  const div = document.createElement('div')
  vm = createVNode(Message)
  render(vm, div)
  document.body.appendChild(div)
}
 
export default function message (content = '', duration) {
  getMessageInstance()
  vm.component.exposed?.add({
    content,
    duration
  })
}